package org.example.aidemo.service.security;

import lombok.Data;
import org.example.aidemo.pojo.User;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

@Data
public class CustomUserDetails implements UserDetails {
    private String username;
    private String password;
    private Long id;
    private int status;
    private Collection<? extends GrantedAuthority> authorities;
    private boolean accountNonExpired;
    private boolean accountNonLocked;
    private boolean credentialsNonExpired;
    private boolean enabled;
    // 构造函数
    public CustomUserDetails(String username, String password,
                             Collection<? extends GrantedAuthority> authorities) {
        this.username = username;
        this.password = password;
        this.authorities = authorities;
        // 设置其他状态...
    }
    public void setUserInfo(User user){
        this.username = user.getUsername();
        this.password = user.getPasswordHash();
        this.status = user.getStatus();
    }
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }


}